package test3_17.Account;

public class Account {

    /*
    写一个名为Account的类模拟账户。该类的属性和方法如下图所示。
     */
    //该类包括的属性：账号id，余额balance，年利率annualInterestRate；
    protected String id;
    protected double balance;
    protected double annualInterestRate;

    public Account(String id, double balance, double annualInterestRate) {
        this.id = id;
        this.balance = balance;
        this.annualInterestRate = annualInterestRate;
    }

    //访问器方法（getter和setter方法）
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    //返回月利率的方法getMonthlyInterest()
    public double getMonthlyInterest(){
        return annualInterestRate/12;
    }

    //取款方法withdraw()，存款方法deposit()。
    public void withdraw (double amount){
        if(amount>0 && amount<=balance){
            balance -= amount;
            System.out.println("账户余额："+balance);
        }else {
            System.out.println("账户余额："+balance);
            System.out.println("余额不足无法取钱");
        }
    }

    public void deposit (double amount){
        balance += amount;
        System.out.println("账户余额："+balance);
    }

}
